package io.eleKing.boot.weather.controller;

import io.eleKing.boot.auth.annotation.Permission;
import io.eleKing.boot.common.enums.SysLogType;
import io.eleKing.boot.framework.annotation.Log;
import io.eleKing.boot.framework.page.Paging;
import io.eleKing.boot.framework.response.ApiResult;
import io.eleKing.boot.weather.dto.WeatherRealDataDto;
import io.eleKing.boot.weather.query.WeatherRealDataQuery;
import io.eleKing.boot.weather.service.WeatherRealDataService;
import io.eleKing.boot.weather.vo.WeatherRealDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *  控制器
 *
 * @author eleKing
 * @since 2025-04-15
 */
@Slf4j
@RestController
// 
@RequestMapping("/admin/weatherRealData")
public class WeatherRealDataController {

    @Autowired
    private WeatherRealDataService weatherRealDataService;

    /**
     * 添加null
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    // 添加null
    @PostMapping("/addWeatherRealData")
    @Permission("weather:real:data:add")
    public ApiResult addWeatherRealData(@Valid @RequestBody WeatherRealDataDto dto) {
        log.info("添加null：{}", dto);
        boolean flag = weatherRealDataService.addWeatherRealData(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改null
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    // 修改null
    @PostMapping("/updateWeatherRealData")
    @Permission("weather:real:data:update")
    public ApiResult updateWeatherRealData(@Valid @RequestBody WeatherRealDataDto dto) {
        log.info("修改null：{}", dto);
        boolean flag = weatherRealDataService.updateWeatherRealData(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除null
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    // 删除null
    @PostMapping("/deleteWeatherRealData/{id}")
    @Permission("weather:real:data:delete")
    public ApiResult deleteWeatherRealData(@PathVariable Long id) {
        log.info("删除null：{}", id);
        boolean flag = weatherRealDataService.deleteWeatherRealData(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取null详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    // 获取null详情
    @PostMapping("/getWeatherRealData/{id}")
    @Permission("weather:real:data:info")
    public ApiResult<WeatherRealDataVo> getWeatherRealData(@PathVariable Long id) {
        log.info("获取null详情：{}", id);
        WeatherRealDataVo weatherRealDataVo = weatherRealDataService.getWeatherRealDataById(id);
        return ApiResult.success(weatherRealDataVo);
    }

    /**
     * 获取null分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    // 获取null分页列表
    @PostMapping("/getWeatherRealDataPage")
    @Permission("weather:real:data:page")
    public ApiResult<WeatherRealDataVo> getWeatherRealDataPage(@Valid @RequestBody WeatherRealDataQuery query) {
        log.info("获取null分页列表：{}", query);
        Paging<WeatherRealDataVo> paging = weatherRealDataService.getWeatherRealDataPage(query);
        return ApiResult.success(paging);
    }

}
